﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;
using System.Data;

namespace ConfExpert.Forms.Depo
{
    public partial class MuadilKodlar : XForm
    {
        int CustomerId;
        public MuadilKodlar(int CustomerId)
        {
            InitializeComponent();
            this.CustomerId = CustomerId;
        }

        DataSet d;
        private void MuadilKodlar_Load(object sender, EventArgs e)
        {
            Rfrsh();
            btnKaydet.ItemClick += btnKaydet_ItemClick;

        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.Update("Muadil2Id,ProductId,AlternatifId", "Muadil2");
            Rfrsh(ExecuteDataTable("UpdMuadil", gridView2.Serialize(), CustomerId));
            RefreshLookups();
        }

        private void Rfrsh(DataTable dt = null)
        {
            d = ExecuteDataSet("GetKodListesi", "YeniVeMuadil", CustomerId);
            gridView2.Init(dt != null ? dt : d.Tables[0]);
            gridView1.Init(d.Tables[1]);

            gridView1.SetViewCaption("Mevcut Muadillerin listesi");
            gridView2.SetViewCaption("Yeni Eklenecek");
            gridView1.Columns["AlternatifId"].ColumnEdit = RI(Rp.V_Kumas);
            gridView1.MakeColumnInvisible("Tarih", "Muadil2Id", "CustomerId");
            gridView2.FocusedRowChanged -= gridView2_FocusedRowChanged;
            gridView2.FocusedRowChanged += gridView2_FocusedRowChanged;

            gridView2.EnableNewRow();
            gridView1.MakeReadOnly();
            gridView2.AddSummary();
            gridView1.AddSummary();
            gridView2.BestFitColumns();
            gridView1.BestFitColumns();
            Notify("Güncellendi");
        }

        void gridView2_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

    }
}
